using System;
using FireStarterModeller.BO;
using FireStarterModeller.Logic;
using Habanero.BO.ClassDefinition;

namespace Firestarter.DB_DomainModel.Logic
{
    public class DBToDMImporterFactory : IDBToDMImporterFactory
    {
        private IRelationshipNameGenerator RelationshipNameGenerator { get; set; }
        private IDBTypeToDMPropertyTypeMapper DMPropertyTypeMapper { get; set; }

        public DBToDMImporterFactory(IDBTypeToDMPropertyTypeMapper dmPropertyTypeMapper, IRelationshipNameGenerator relationshipNameGenerator)
        {
            if (dmPropertyTypeMapper == null) throw new ArgumentNullException("dmPropertyTypeMapper");
            if (relationshipNameGenerator == null) throw new ArgumentNullException("relationshipNameGenerator");
            DMPropertyTypeMapper = dmPropertyTypeMapper;
            RelationshipNameGenerator = relationshipNameGenerator;
        }

        public IDBChangesImporter CreateDBChangesImporter()
        {
            return new DBChangesImporter(this);
        }

        public IDBToDMClassImporter CreateDBToDMClassImporter()
        {
            return new DBToDMClassImporter();
        }

        public IDBToDMPropertyImporter CreateDBToDMPropertyImporter()
        {
            return new DBToDMPropertyImporter(CreateDBToDMPropertyUpdater());
        }

        private IDBToDMPropertyUpdater CreateDBToDMPropertyUpdater()
        {
            return new DBToDMPropertyUpdater(DMPropertyTypeMapper);
        }

        public IDBToDMObjectIdentityImporter CreateDBToDMObjectIdentityImporter()
        {
            return new DBToDMObjectIdentityImporter();
        }

        public IDBToDMUniqueConstraintImporter CreateDBToDMUniqueConstraintImporter()
        {
            return new DBToDMUniqueConstraintImporter();
        }

        public IDBToDMRelationshipImporter CreateDBToDMRelationshipImporter()
        {
            return new DBToDMRelationshipImporter(RelationshipNameGenerator);
        }
    }
}